-
Notifications
You must be signed in to change notification settings - Fork 8k
usb: host: class: support for usb host video class #94085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
usb: host: class: support for usb host video class #94085
Conversation
AidenHu
commented
Aug 4, 2025
- Add USB host video class driver usbh_uvc.c/h . This class driver is implemented based on UVC 1.5
- The USB host video class driver is tightly coupled with the video subsystem. Users still use video API to operate it.
- Some key changes for usbh_core.c to support multiple classes that one USB device supports.
- Some necessary changes to make video capture example connect with USB device camera based on the new USB host video class driver.
Hello @AidenHu, and thank you very much for your first pull request to the Zephyr project! |
669c434
to
4ca6d07
Compare
uvc_host: uvc_host { | ||
compatible = "zephyr,uvc-host"; | ||
}; | ||
}; No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need blank line (repeat this on a couple of the files)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need blank line (repeat this on a couple of the files)
Thanks, done it.
#include <zephyr/kernel.h> | ||
#include <zephyr/device.h> | ||
|
||
#include <zephyr/drivers/display.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is draft but I think we want to allow this sample to support Video host and video device
@AidenHu you are going to need to break this up into multiple commits. My suggestion is:
|
cb3ab4e
to
76bed79
Compare
76bed79
to
9192550
Compare
Make the struct name match the device naming for ease of use, although slightly longer name. Propagate the change to the subsystem, includes, tests and samples. Signed-off-by: Josuah Demangeon <[email protected]>
Allocate extra room at the end of the USB descriptor buffer to ensure that the device ends with `desc->bLength == 0`. For now, validating `desc->bLength` from the device to ensure no access past the buffer is still not done. Signed-off-by: Josuah Demangeon <[email protected]>
Add a "struct usbh_status" that contains a bitmask of flags to keep track of the global state of the host context, like done for the device_next implementation. Add helpers to check the status. Signed-off-by: Josuah Demangeon <[email protected]>
Hide the mutex lock details inside a wrapper call, like done for the device stack API. This is not used for the per-device lock of the host stack which use a different mutex lock. Signed-off-by: Josuah Demangeon <[email protected]>
Update the USB shell sample to the new syntax. This is based on tests done with native_sim, along with the virtual.conf, virtual.overlay and device_and_host_prj.conf extra config files. Signed-off-by: Josuah Demangeon <[email protected]>
9192550
to
6e8acc7
Compare
Thank you for updating this PR with a more fine-grained commit history. In parallel, I opened #94504 to add the missing USB Host API bits to enable this class to be implemented, using the content of this current PR:
And here is this current PR |
Thank you for the reply, @josuah |
90739a9
to
aef5e85
Compare
Add a "struct usbh_class_api" for the host implementation, and move all the function poitners to it, as it is done for the device support. Add more fields to the host struct usbh_class_data mirrorring the device side struct, including the API pointer. Signed-off-by: Josuah Demangeon <[email protected]>
Add API wrappers around the function pointers in struct usbh_class_api, while also documenting the USB host class internal API. Signed-off-by: Josuah Demangeon <[email protected]>
Add functions to register all classes as part of a new usbh_class.c and a matching usbh_class.h. These functions are called from the function usbh_init_device_intl() in usbh_core.c to initialize every class upon connection of a device. The class instances are registered and connected together as a linked list. Co-authored-by: Aiden Hu <[email protected]> Signed-off-by: Josuah Demangeon <[email protected]>
aef5e85
to
629e311
Compare
41b1fc8
to
9d15e7e
Compare
Hi @josuah |
Understood, thanks for letting me know @AidenHu! |
Update this sample is dedicated to support usb host video. This sample can enumerate UVC device, configure UVC device and start video stream transfers then display it on LCD. Signed-off-by: Aiden Hu <[email protected]>
Add usbh node. Signed-off-by: Aiden Hu <[email protected]>
usb clock enablement for UHC NXP EHCI on rw. Signed-off-by: Aiden Hu <[email protected]>
1. Add interval for usb xfer. 2. Set right mps for during pipe init. 3. Set right direction for non-zero endpoint. 4. Check transferBuffer during init transfer. Signed-off-by: Aiden Hu <[email protected]>
Use right parameters for usbh_class_connected and usbh_class_removed. Signed-off-by: Aiden Hu <[email protected]>
Incorrect start address is used for usbh_class_connected for each supported independent class. Implement dev_removed_handler to properly notify class disconnection event. Signed-off-by: Aiden Hu <[email protected]>
Move the pointer to the next descriptor to prevent incorrect address usage. Signed-off-by: Aiden Hu <[email protected]>
Change the default value for QH/QTD/ITD/SITD of usb host ehci. Signed-off-by: Aiden Hu <[email protected]>
1. Delete uvc_guid_map and related functions, use the database and helper functions from usb_common_uvc.c 2. Rename uvc_host_parse_frame_intervals as uvc_host_parse_frame_default_intervals to select default frame interval. 3. Correct uvc_host_select_streaming_alternate to do right alternate selection. 4. Implement uvc_host_removed function. 5. Enhance the video_usb_uvc_host_set_stream function. Signed-off-by: Aiden Hu <[email protected]>
1. Use common usb_uvc.h header for usbh_uvc.c 2. Delete common definitions from usbh_uvc.h 3. Clean up and optimize usbh_uvc.c 4. Add necessary symbols for usb host uvc class. Signed-off-by: Aiden Hu <[email protected]>
Some necessary definitions are added. Do some improvements for the existing content based on the UVC spec. Signed-off-by: Aiden Hu <[email protected]>
9d15e7e
to
1ce0e22
Compare
Adjust video stream callback function to be more robust. Use multiple primes to improve the throughput. Signed-off-by: Aiden Hu <[email protected]>
This new symbol is used to set usb transfer prime count. Signed-off-by: Aiden Hu <[email protected]>
Set proper value for some resources. Use configurable fps. Signed-off-by: Aiden Hu <[email protected]>
@josuah, I have pushed another 3 commits to enhance the video stream transfer and optimize resource usage. |
There is a discussion about how to handle various aspects of the class API in: So as of now, API1 is merged, and API2 is going to have slight modifications. Something which can help getting favorable review is to get the CI passing. Thank you for the update! |
The current roadmap as I understand it:
I think this would ready to merge after this. Future improvement on the side of video can be done on follow-up PR to cover more features. Would that make sense? |
@josuah, |
.type = UVC_CONTROL_SIGNED, | ||
}, | ||
{ | ||
.size = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @josuah,
Here the size should be 2 for PU_CONTRAST_CONTROL
1. Use the uvc_control_map from usb_common_uvc.c. 2. Use GET_MIN/GET_MAX/GET_RES/GET_DEF request to query device. 3. Unify the handling for single video control Signed-off-by: Aiden Hu <[email protected]>
video_find_ctrl becomes an API. Signed-off-by: Aiden Hu <[email protected]>
481d326
to
7af56c4
Compare
|